function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        var r = window.location.search.substr(1).match(reg);  //匹配目标参数
        if (r != null) return unescape(r[2]); return null; //返回参数值
    }

$.fn.serializeObject = function () {
    var o = {};
    var a = this.serializeArray();
    $.each(a, function () {
        if (o[this.name]) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};

//表单提交提示正在提交中
var submitLoad = function() {
    var _PageHeight = document.documentElement.clientHeight,
        _PageWidth = document.documentElement.clientWidth;

    var _DivTop = (document.documentElement.clientHeight - _PageHeight) / 2,
        _DivLeft = (document.documentElement.clientWidth - _PageWidth) / 2;

    var _LoadingTop = _PageHeight > 60 ? (_PageHeight - 60) / 2 : 0,
        _LoadingLeft = _PageWidth > 120 ? (_PageWidth - 120) / 2 : 0;

    var Loadimagerul = "../../images/loading.gif",
        linkImg = '<img src="' + Loadimagerul + '" style="z-index:10002">';

    var _LoadingHtml =
        '<div id="loadingDiv" style="position:absolute;left:' +
        +_DivLeft + 'px;top:'
        + _DivTop + 'px;height:'
        + _PageHeight + 'px;width:'
        + _PageWidth + 'px;opacity:0.6;filter:alpha(opacity=80);z-index:10000;">'
        + '<div style="position: absolute; cursor1: wait; left:0; top:0; width:100%; height: 100%; line-height: 57px; padding-left: 10px; '
        + 'padding-right: 5px; border: 0px solid #95B8E7; color: #696969;background-color:#e6e6e6;z-index:10000">'
        + '<div style="align:center;width:150px; height: 57px;margin-top: 18%;'
        + 'margin-left: 45%;">' + linkImg + '<span style="vertical-align: super;font-size:18px;color:#262626">正在提交<span>...</div></div>';

    $('body').append('<div id="loadDiv"></div>');

    $('#loadDiv').html(_LoadingHtml);

};
//移除正在提交中
var removeLoad = function(){
    var flag = $('#loadDiv').length;
    if (flag == 1) {
        $('#loadDiv').remove();
    }
};
//根据人员编号导出到excel
function exportAsExcelByRybh(sub_url, tableid, jbxxid) {
    var jbxx = $('#' + jbxxid).datagrid('getSelected');
    if (jbxx) {
        var rybh = jbxx.rybh;
    } else {
        $.messager.alert('提示', '请选择一位人员的记录导出！');
        return;
    }
    var total = $('#' + tableid).datagrid("getData").total;
    if (total==0){
        $.messager.alert('提示', '该人员记录为空无法导出！');
        return;
    }
    var opt = $('#' + tableid).datagrid("options");
    $.messager.confirm('提示', '确定要导出' + opt.title + '的数据吗？', function (r) {
        if (r) {
            var result = {
                'field': getTableField(tableid),
                'title': opt.title + '表',
                'rybh': rybh,
            }
            $.ajax({
                type: "POST",  //提交方式
                url: "/" + sub_url + "/SubmitExcelData",//路径
                data: JSON.stringify(result),
                contentType: 'application/json;charsetset=UTF-8',
                success: function (result) {
                    if (result) {
                        window.location.href = "/" + sub_url + "/partExport"
                    } else {
                        $.messager.alert("确定", "导出失败！", "info");
                    }
                }
            });
        }
    })
}

//封装导出需要的字段
var getTableField = function (tableid) {
    var opt = $('#' + tableid).datagrid("options");
    var columns = opt.columns[0];
    var titleList = [];
    var name;
    for (var i = 2; i < columns.length; i++) {
        var map = {
            name: columns[i].field,
            value: columns[i].title,
        }
        titleList.push(map);
        console.log(map.value);
    }
    return titleList;
}

//导出到excel
function exportAsExcel(sub_url,tableid,result) {
    if(tableid == 'thjyDetailId'){
        var total = $('#thjyDetailId').datagrid("getData").total;
    }else{
        var total = $('#' + tableid).datagrid("getData").total;
    }
    if (total==0){
        $.messager.alert('提示', '记录为空无法导出！');
        return;
    }
    var opt = $('#' + tableid).datagrid("options");
    $.messager.confirm('提示', '确定要导出' + opt.title + '的数据吗？', function (r) {
        if (r) {
            var data_rows = $('#' + tableid).datagrid('getData').rows;
            result['field'] = getTableField(tableid);
            result['title'] = opt.title + '表';
            $.ajax({
                type: "POST",  //提交方式
                url: "/" + sub_url + "/SubmitExcelData",//路径
                data: JSON.stringify(result),
                contentType: 'application/json;charsetset=UTF-8',
                success: function (result) {
                    if (result) {
                        window.location.href = "/" + sub_url + "/partExport"
                    } else {
                        $.messager.alert("确定", "导出失败！", "info");
                    }
                }
            });
        }
    })
};


var echoCache = function(div_id,sub_key){
	var obj = {};
	var keyList = [];
	var keyString = [];
	$.ajax({ 
		type : "POST",  //提交方式  
		//async : false,
		url : "/getEchoFormData",//路径  
		data : {
			"key":sub_key,
		},
		success : function(result) {
			if (result.status == 200) {
				obj = result.result.jsonObj;
				keyList = result.result.keySet;
				//keyString = result.result.keyString;
				var reg1 = 'awdSelect';
				var reg2 = 'easyui-combo';
				//var reg1 = RegExp(/awdSelect/);
				//var reg2 =  RegExp(/easyui-combo/);
				for (var i = 0; i < keyList.length; i++) {
					var name = keyList[i];
					//var id = $("#"+div_id+" input[name='"+name+"']").parent().prev().attr("id");
					var id = $("#"+div_id+" input[textboxname='"+name+"']").attr("id");
					if(id!=undefined){
						var className = document.getElementById(id).className;
						//reg1.test($(className)) || reg2.test($(className))
						if(className.indexOf(reg1) != -1 || className.indexOf(reg2) != -1){
							if ($('#'+id).attr("checkBox")=="true") {
								$("#"+id).combo("setValues",obj[name]);
							}else {
								$("#"+id).combo("setValue",obj[name]);
							}
							$("#"+id).combo("setText",obj[name+"String"]);
						}else {
							$("#"+id).textbox("setValue",obj[name]);
						}
					}
				}
			}else if (result.status == 300) {
				$.messager.alert("确定", result.message, "info");
			}
		},
		error : function(){
			$.messager.alert("确定", "无法获取历史数据缓存信息!", "info");
		},
    });
}

Date.prototype.format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

var currentTime = function(){
    return new Date().format('yyyy-MM-dd hh:mm:ss')
}

var currentDate = function(){
    return new Date().format('yyyy-MM-dd')
}


function timeType(date) { // 短日期格式化
    var datetime = date.getFullYear()
        + "-"// "年"
        + ((date.getMonth() + 1) > 10 ? (date.getMonth() + 1) : "0"
            + (date.getMonth() + 1))
        + "-"// "月"
        + (date.getDate() < 10 ? "0" + date.getDate() : date
            .getDate());
    return datetime;
};


function longTimeType(date) { //转换为 类似 2018-04-21 16:08:52 等格式的长日期
  var sfm = date.toTimeString().split(' ')[0];
  var datetime = date.getFullYear() 
  + "-" 
  + ((date.getMonth() + 1) > 10 ? (date.getMonth() + 1) : "0"
        + (date.getMonth() + 1)) 
  + "-"
  + (date.getDate() < 10 ? "0" + date.getDate() : date
            .getDate()) 
  + " " 
  + sfm;
  return datetime;
}

//用一个开始时间加上天数得出结果时间 -- 返回短日期格式
function getShortDatePlus(startDate , dayCount) {
var ksDate = new Date(startDate);
thisDate = new Date((ksDate/1000+(86400*dayCount))*1000);
return timeType(thisDate);
}  

//用一个开始时间加上天数得出结果时间 -- 返回长日期格式 ------还没测试
function getLongDatePlus(startDate , dayCount) {
var sfm = startDate.split(' ')[1]; //切割获取时分秒
var nyr = startDate.split(' ')[0]; //切割获取年月日
var ksDate = new Date(nyr);
thisDate = new Date((ksDate/1000+(86400*dayCount))*1000);
new_date = timeType(thisDate) + ' ' + sfm ;
return new_date;
}

function formatDate(time) {
    var date = new Date(time); // 增加8小时
    return date.toJSON().substr(0, 19).replace('T', ' ');
}
